package com.hnevc.musicplayer;

import android.app.Service;
import android.content.Intent;
import android.media.MediaParser;
import android.media.MediaPlayer;
import android.os.IBinder;

import androidx.annotation.Nullable;

import java.util.Timer;
import java.util.TimerTask;

public class MusicService extends Service {

    private MediaPlayer player;

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        //开启创建音乐播放器对象
        player = new MediaPlayer();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
    //开启计时器用于设置音乐播放器中的播放进度条
    public  void addTimer(){
        Timer timer = new Timer(); //创建计时器对象
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                //重复做的事情
                if (player == null)return;
                    //获取音乐的时长
                    int duration = player.getDuration();

            }
        };
        timer.schedule(task,5,500);
    }
}
